#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <algorithm>
#include <string>
using namespace std;
#include <QFileDialog>
#include <QMessagebox>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    doPaint = false;
    connect(ui->actionStart, SIGNAL(triggered()), this, SLOT(StartPaint()));
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::paintEvent(QPaintEvent *)
{
    if (!doPaint)
        return;

    QPainter painter(this);
    for (int i=0; i<1000; i++)
    {
        painter.setPen(c[i]);
        painter.drawArc(x[i], y[i], rad[i], rad[i], 0, 16 * 360);
    }
}

void MainWindow::StartPaint()
{
    for (int i=0; i<1000; i++)
    {
        int topBorder = ui->menuBar->height()-ui->mainToolBar->height();
        int maxWidth = std::min(this->width(), this->height()-topBorder);
        rad[i] = rand() % (maxWidth);
        x[i] = rand() % (this->width()-rad[i]);
        y[i] = rand() % (this->height()-topBorder-rad[i]) + topBorder;
        c[i].setRed(rand()%256);
        c[i].setGreen(rand()%256);
        c[i].setBlue(rand()%256);
    }

    doPaint = true;
    this->repaint();
}


void MainWindow::on_action_Open_triggered()
{
    string fileName = QFileDialog::getOpenFileName(this,
            tr("Open Sequence File"), "",
            tr("DNA Sequence Files (*.fasta;*.fasta.gz;*.fastq;*.fastq.gz)")).toStdString();

    if (fileName.empty())
        return;
    else
        QMessageBox((string("You selected to open file ")+fileName).c_str());

}
